package com.ll.fof;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

public class FofJobTwo {

	public static void main(String[] args) throws Exception {
		Configuration conf = new Configuration();
		conf.set("fs.defaultFS", "hdfs://node2:8020");
		conf.set("yarn.resourcemanager.hostname", "node3");
		Job job = Job.getInstance(conf);
		job.setJarByClass(FofJobOne.class);
		
		job.setMapperClass(FofMapperTwo.class);
		job.setMapOutputKeyClass(Friend.class);
		job.setMapOutputValueClass(IntWritable.class);
		job.setGroupingComparatorClass(FofGroup.class);
		job.setSortComparatorClass(FofSort.class);
		job.setReducerClass(FofReducerTwo.class);
		FileInputFormat.addInputPath(job, new Path("/fof/output1/"));
		Path outpath = new Path("/fof/output2");
		FileSystem fs = FileSystem.get(conf);
		if (fs.exists(outpath)) {
			fs.delete(outpath,true);
		}
		FileOutputFormat.setOutputPath(job, outpath);
		boolean flag = job.waitForCompletion(true);
		if (flag) {
			System.out.println("job success");
		}
		
	}
}
